bin=ihub
binPath=${GOPATH}/out/${module}/${bin}
imgName=docker.io/cfxl/ihub-agent:latest

alpine:
	docker run --rm --name ihub_agent_build --net host \
	-w ${groupPath} \
	-v ${groupPath}:${groupPath} \
	--env GOPATH=${GOPATH} \
	golang:alpine sh -c " go build -ldflags '-w -s' -o ${binPath} ${modulePath}/cmd/main.go \
	&& ls -lh ${GOPATH}/out/${module}"

x86:  #x86架构编译
	@echo "use GOPATH: ${GOPATH}"
	GOPATH=${GOPATH} go build -ldflags "-w -s" -o ${binPath} ${modulePath}/cmd/main.go

test2: build
	docker run --rm -it --net host \
	${imgName} agent --c="nginx -g 'daemon off;'" --eds="http://copyer.default.hubx.site:30080/event2"

build: gen x86
	cp ${modulePath}/build/nginx.conf ${GOPATH}/out && \
	cd ${GOPATH}/out && \
	docker build -t ${imgName} -f ${modulePath}/build/Dockerfile ./
push:
	docker push ${imgName}

gen:
	PATH=${GOPATH}/bin:$${PATH} go-bindata -ignore bindata.go -ignore bindata_test.go \
	-pkg tpl \
	-o agent/pkg/tpl/bindata.go \
	agent/pkg/tpl

deploy:
	scp -P 2202 agent/build/docker-compose.yaml root@lb.hubx.site:/root/apps/docker-registry

package:
	@cp agent/build/docker-compose.yaml ~/apps/repx/hubx/roles/registry/templates/docker-compose.yaml.j2 && \
	sed -i 's/9091/{{httpPort}}/g' ~/apps/repx/hubx/roles/registry/templates/docker-compose.yaml.j2